import * as CookiesSave from '@/utils/auth'

const state = {
  tsn: CookiesSave.getTsn(),
  csn: CookiesSave.getCsn(),
  audittype: CookiesSave.getAudittype()
}

const mutations = {
  SET_TSN: (state, tsn) => {
    state.tsn = tsn
  },
  SET_CSN: (state, csn) => {
    state.csn = csn
  },
  SET_AUDITTYPE: (state, audittype) => {
    state.audittype = audittype
  }
}

const actions = {
    auditSn({ commit }, auditInfo) {
      const { t_sn, c_sn, auditType } = auditInfo
      return new Promise((resolve, reject) => {
        commit('SET_TSN', t_sn)
        CookiesSave.setTsn(t_sn)
        commit('SET_CSN', c_sn)
        CookiesSave.setCsn(c_sn)
        commit('SET_AUDITTYPE', auditType)
        CookiesSave.setAudittype(auditType)
        resolve()
      })
    }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
